home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1996 #3 / AmigaPlus_CD-ROM-EXTRA_Nr.3.bin / aminet-spiele / zwei spieler / lordofhosts / lohsrc.lzh / misc.c < prev    next >
C/C++ Source or Header  |  1991-05-10  |  12KB  |  378 lines

  1. /* LORD OF HOSTS - misc.c --- Verschiedene Dienstleistungsroutinen */
  2.  
  3. #include "Lord.h"
  4.  
  5. extern ULONG JoyMouseData;
  6. char players[2][16];
  7. extern int status;
  8. extern BOOL joymouse_on, joymouse_allowed;
  9.  
  10. struct TRStructure MyTextStruct;
  11.  
  12. void Rules(void)
  13. {
  14.    short result=0;
  15.    int nr=-1;
  16.    MyTextStruct.KeyMask=0xFFFF;
  17.    MyTextStruct.textcolor=1;
  18.     MyTextStruct.detailcolor = 0;
  19.     MyTextStruct.blockcolor = 1;
  20.     MyTextStruct.versionnumber = 0;
  21.     MyTextStruct.rfu1 = 0;
  22.     MyTextStruct.rfu2 = 0;
  23.    while (result!=1)
  24.    {
  25.       if (result==0) ++nr;
  26.       if (result==2) --nr;
  27.       switch (nr)
  28.       {
  29.          case 0:
  30.          MyTextStruct.Title="Rules: Page 1";
  31.          MyTextStruct.PositiveText = "Resume";
  32.          MyTextStruct.NegativeText = "Next Page";
  33.          MyTextStruct.MiddleText = NULL;
  34.          MyTextStruct.Text =
  35. "            LORD OF HOSTS\n"
  36. "            =============\n\n"
  37. "Each  player  controls  seven  Knights\n"
  38. "and one King  (that's the one with the\n"
  39. "crown).   The  aim  of  the game is to\n"
  40. "defeat the opponent by:\n"
  41. " - capturing his King  or\n"
  42. " - beating all but one of his Knights\n\n"
  43. "Players  should  aim  to  attack their\n"
  44. "opponent's   pieces   while  defending\n"
  45. "their own.\n\n\n\n\n\n";
  46.          break;
  47.          case 1:
  48.          MyTextStruct.Title="Rules: Page 2";
  49.          MyTextStruct.PositiveText = "Resume";
  50.          MyTextStruct.NegativeText = "Next Page";
  51.          MyTextStruct.MiddleText = "Prev Page";
  52.          MyTextStruct.Text =
  53. "             How To Play\n\n"
  54. "Select  'Begin  Game'  (Game Menu) and\n"
  55. "enter  your and your opponent's names.\n"
  56. "The  computer  decides  who will start\n"
  57. "the game.\n"
  58. "Player 1 uses the mouse to control the\n"
  59. "pointer;  Player 2 can use a joystick.\n"
  60. "After  one  player  has  finished  his\n"
  61. "move, control over the pointer will be\n"
  62. "given to his opponent.\n"
  63. "On the right side  of the screen there\n"
  64. "are two boxes containing  the names of\n"
  65. "the players.  They also indicate whose\n"
  66. "turn  it is  by changing  the color of\n"
  67. "the words 'Player 1/2' to blue.\n"
  68. "The  color  changes to yellow when the\n"
  69. "computer  is waiting  for a move to be\n"
  70. "confirmed (see page 9).";
  71.          break;
  72.          case 2:
  73.          MyTextStruct.Title="Rules: Page 3";
  74.          MyTextStruct.Text =
  75. "             How To Move\n\n"
  76. "Click   once  (left  mouse  button  or\n"
  77. "joystick  fire  button) over the piece\n"
  78. "you   want   to   move.    The  number\n"
  79. "indicated  on  the piece is the number\n"
  80. "of squares this piece HAS GOT TO move.\n"
  81. "The   pieces   can   only   be   moved\n"
  82. "horizontally    or   vertically   (NOT\n"
  83. "diagonally);  however, you are allowed\n"
  84. "one  right-angle-turn  per move.  That\n"
  85. "is, a value of 4 might be used to move\n"
  86. "the  piece  1  square  up and 3 to the\n"
  87. "left.\n"
  88. "A  piece  can't  jump  over  any other\n"
  89. "piece.    Also,  a  piece  can't  move\n"
  90. "forwards  and backwards  in  one move.\n\n";
  91.          break;
  92.          case 3:
  93.          MyTextStruct.Title="Rules: Page 4";
  94.          MyTextStruct.Text =
  95. "         How To Move (cont'd)\n\n"
  96. "Click  once on the square you want the\n"
  97. "selected  piece  to  move  to.  If the\n"
  98. "move  is  valid,  the  piece will move\n"
  99. "there.   If  it  isn't, you can select\n"
  100. "another  square  or  another  piece to\n"
  101. "move   with.    You   can   obtain  an\n"
  102. "explanation   for   why  the  computer\n"
  103. "refused   to   move   your   piece  by\n"
  104. "selecting   'Explain   Invalid   Move'\n"
  105. "(Special Menu).\n"
  106. "A move is invalid if\n"
  107. " - you try to move too far\n"
  108. " - you don't move far enough\n"
  109. " - the way is blocked\n"
  110. " - an  opponent's piece  can beat your\n"
  111. "   King (just like in chess).\n";
  112.          break;
  113.          case 4:
  114.          MyTextStruct.Title="Rules: Page 5";
  115.          MyTextStruct.Text =
  116. "            How to Capture\n\n"
  117. "Any  piece  can  capture  any  of  the\n"
  118. "opponent's  pieces  by  landing on the\n"
  119. "square  occupied  by the piece  at the\n"
  120. "end of a move.  The King  is  the only\n"
  121. "piece  that cannot be captured in this\n"
  122. "way. If a King is standing on a square\n"
  123. "where  he  could  be captured, 'Check'\n"
  124. "is announced.   In the following move,\n"
  125. "the  attacked player must either\n"
  126. " - move his King out of danger or\n"
  127. " - block the way  between the King and\n"
  128. "   the  threatening piece with another\n"
  129. "   piece or\n"
  130. " - capture the threatening piece.\n"
  131. "If  he  is  unable to do any of these,\n"
  132. "the game is over.\n";
  133.          break;
  134.          case 5:
  135.          MyTextStruct.Title="Rules: Page 6";
  136.          MyTextStruct.Text =
  137. "         The End Of The Game\n\n"
  138. "As indicated on the previous page, the\n"
  139. "game  is  over when one of the players\n"
  140. "can't  do  any  valid  moves  anymore.\n"
  141. "Another  way  of ending the game is to\n"
  142. "capture  all of the opponent's Knights\n"
  143. "except  for  one.   A player who finds\n"
  144. "himself  with  only  his  King and one\n"
  145. "Knight has lost the battle.\n\n\n\n\n\n\n\n\n";
  146.          break;
  147.          case 6:
  148.          MyTextStruct.Title="Rules: Page 7";
  149.          MyTextStruct.Text =
  150. "     Explanation Of The Menus (1)\n\n"
  151. "GAME Menu:\n"
  152. "Begin Game : Begin a new game.\n"
  153. "Load Game  : Load a game.\n"
  154. "Save Game  : Save current game.    The\n"
  155. " whole game  will  be  saved (not only\n"
  156. " the current positions).\n"
  157. "Rules      : Guess what.\n"
  158. "About      : Some infos about LORD.\n"
  159. "Quit       : Well, quit.\n\n\n\n\n\n\n\n";
  160.          break;
  161.          case 7:
  162.          MyTextStruct.Title="Rules: Page 8";
  163.          MyTextStruct.Text =
  164. "     Explanation Of The Menus (2)\n\n"
  165. "BOARD Menu:\n"
  166. "Standard   : Lord Of Hosts is based on\n"
  167. " a board game. The  pieces' values are\n"
  168. " determined by  little  magnets inside\n"
  169. " the  board. This is the simulation of\n"
  170. " the original board.\n"
  171. "Rotated  90°: Same  board,  rotated by\n"
  172. " 90°  (results   in  different  number\n"
  173. " patterns).\n"
  174. "Balanced Rnd:  Computer generated ran-\n"
  175. " dom board.   However, the 64 possible\n"
  176. " values (8*8)  are  distributed evenly\n"
  177. " to each piece (16*1,16*2,etc.)\n"
  178. "Unbalanced  : No even distribution of \n"
  179. " piece values.\n\n";
  180.          break;
  181.          case 8:
  182.          MyTextStruct.Title="Rules: Page 9";
  183.          MyTextStruct.PositiveText = "Resume";
  184.          MyTextStruct.NegativeText = "Next Page";
  185.          MyTextStruct.MiddleText = "Prev Page";
  186.          MyTextStruct.Text =
  187. "     Explanation Of The Menus (3)\n"
  188. "SPECIAL Menu:\n"
  189. "Undo :  Undoes last move.  Can be used\n"
  190. " to undo  the last 500 moves one after\n"
  191. " another. Most games are much shorter.\n"
  192. " Works also with loaded games!\n"
  193. "Redo  :  Redoes one move that has been\n"
  194. " previously  undone.  Can only work if\n"
  195. " no new  moves have occurred since the\n"
  196. " last 'Undo'.\n"
  197. "Help Mode :  The computer can help you\n"
  198. " in  deciding  which move to  do.   By\n"
  199. " selecting 'Show Known Values' you are\n"
  200. " given a  chance  to  look  at the new\n"
  201. " value the  piece  will have after the\n"
  202. " move IF  THE  PIECE  HAS  BEEN  THERE\n"
  203. " BEFORE. 'Show All Values' will always\n"
  204. " show  the new value.  You can confirm\n"
  205. " the move (click dest.) or try again.";
  206.          break;
  207.          case 9:
  208.          MyTextStruct.Title="Rules: Page 10";
  209.          MyTextStruct.PositiveText = "Resume";
  210.          MyTextStruct.NegativeText = NULL;
  211.          MyTextStruct.MiddleText = "Prev Page";
  212.          MyTextStruct.Text =
  213. "     Explanation Of The Menus (3)\n\n"
  214. "SPECIAL Menu (cont'd):\n"
  215. "JoyMouse  :   If  you don't  wish that\n"
  216. " player 2  should  use a  joystick  to\n"
  217. " move the mouse  pointer, you can turn\n"
  218. " off this feature by selecting 'off'. \n"
  219. "Set  JoyMouse  Speed  :   If you don't\n"
  220. " like the  mouse  pointer's speed when\n"
  221. " steered by  Joystick,  you can change\n"
  222. " it with this menu item.  Useful  with\n"
  223. " mouse accelerators.\n"
  224. "Switch Sides : Currently unimplemented\n"
  225. " feature  for  the  version of LORD in\n"
  226. " which you will be playing against the\n"
  227. " COMPUTER...\n"
  228. "Explain  Invalid  Move  :  Brings up a\n"
  229. " requester telling  you  why  the last\n"
  230. " move had to be rejected.";
  231.          break;
  232.          default:
  233.          MyTextStruct.Text = NULL;
  234.          break;
  235.       }
  236.       result = TextRequest(&MyTextStruct);
  237.    }
  238. }
  239.  
  240. void About(void)
  241. {
  242.    SimpleRequest(
  243. "          LORD OF HOSTS V1.0\n"
  244. "          ==================\n\n"
  245. "            Programmed by:\n"
  246. "            Tim Pietzcker\n"
  247. "          Schwarzwaldstr.52\n"
  248. "      W-7819 Denzlingen, Germany\n"
  249. "Copyright © 1991. All Rights Reserved.\n\n"
  250. "Many  thanks  to the developers of the\n"
  251. "CygnusEd Pro (Release 2) for both this\n"
  252. "great editor and the req.library!\n"
  253. "  Written in ANSI C (Aztec C V5.0d)\n\n"
  254. "This program may be freely distributed\n"
  255. "as long as this notice remains intact.\n"
  256. "Distribution  in  PD series other than\n"
  257. "Fred Fish's  requires  written permis-\n"
  258. "sion from the author (that's me!).");
  259. }
  260.  
  261. void ExplainError(int Error)
  262. {
  263.    char errtext[300]="The last move I rejected was invalid\nbecause";
  264.    if (!Error) strcpy(errtext,"There has been no invalid move");
  265.    if (Error & DIST_EXCEEDED)
  266.       strcat(errtext,"\n - you'd have moved the piece too far");
  267.    if (Error & MUST_MOVE_FARTHER)
  268.       strcat(errtext,"\n - you didn't move far enough");
  269.    if (Error & WAY_BLOCKED)
  270.       strcat(errtext,"\n - the way was blocked");
  271.    if (Error & KING_IN_DANGER)
  272.       strcat(errtext,"\n - your King must not be left\n   exposed to danger");
  273.    strcat(errtext,"!");
  274.    SimpleRequest(errtext);
  275. }
  276.  
  277. void SetJMSpeed(void)
  278. {
  279.     struct GetLongStruct    MyGetLongStruct;
  280.  
  281.     MyGetLongStruct.titlebar = "New JoyMouse Speed:";
  282.     MyGetLongStruct.defaultval = (LONG)JoyMouseData;
  283.     MyGetLongStruct.minlimit = 1;
  284.     MyGetLongStruct.maxlimit = 10;
  285.     MyGetLongStruct.window = 0;
  286.     MyGetLongStruct.versionnumber = 0;
  287.     MyGetLongStruct.flags = 0;
  288.     MyGetLongStruct.rfu2 = 0;
  289.     if (GetLong(&MyGetLongStruct))
  290.    {
  291.       Forbid();
  292.       JoyMouseData=(ULONG)MyGetLongStruct.result;
  293.       Permit();
  294.    }
  295. }
  296.  
  297. void EnterNames(void)
  298. {
  299.    do
  300.       GetString(players[0], "Player 1, please enter your name:", NULL, 38, 16);
  301.    while (strchr((const char *)players[0],'%'));
  302.    do
  303.       GetString(players[1], "Player 2, please enter your name:", NULL, 38, 16);
  304.    while (strchr((const char *)players[1],'%'));
  305.    drawplayers(players[0],players[1]);
  306. }
  307.  
  308. BOOL Coords(SHORT MouseX, SHORT MouseY, UBYTE *x, UBYTE *y)
  309. {
  310.    MouseX-=2; MouseY-=13;
  311.    if (MouseX<0 || MouseY<0 || MouseX>183 || MouseY>183) return FALSE;
  312.    *x = MouseX / 23;
  313.    *y = MouseY / 23;
  314.    return TRUE;
  315. }
  316.  
  317. void Exchange(UBYTE *a, UBYTE *b)
  318. {
  319.    UBYTE c;
  320.    c = *a;
  321.    *a = *b;
  322.    *b = c;
  323. }
  324.  
  325. void Notify(int Nr, int occurrence)
  326. {
  327.    char notice[200];
  328.    if (occurrence == ENEMY_KNIGHT_BEATEN) return;
  329.    occurrence &= (~ENEMY_KNIGHT_BEATEN);
  330.    if (occurrence)
  331.    {
  332.       strcpy(notice,players[Nr]);
  333.       if (occurrence & ENEMY_KING_BEATABLE)
  334.       {
  335.          strcat(notice," announces 'CHECK!'\n");
  336.          if (occurrence > ENEMY_KING_BEATABLE)
  337.             strcat(notice,"and");
  338.       }
  339.       if (occurrence > ENEMY_KING_BEATABLE)
  340.       {
  341.          strcat(notice," wins the game!\n");
  342.          if (occurrence & ENEMY_MATED)
  343.          {
  344.             strcat(notice,players[1-Nr]);
  345.             strcat(notice,"'s King is checkmated !\n");
  346.          }
  347.          if (occurrence & ENEMY_OUT_OF_KNIGHTS)
  348.          {
  349.             strcat(notice,players[1-Nr]);
  350.             strcat(notice," has lost six Knights!\n");
  351.          }
  352.          status &=(~(WAITING_FOR_PICK|WAITING_FOR_DEST|WAITING_FOR_CONF|IN_GAME));
  353.          NextPlayer(RED);  /* schaltet JoyMouse aus und setzt Farben zurück */
  354.       }
  355.       SimpleRequest(notice);
  356.    }
  357. }
  358.  
  359. void NextPlayer(BOOL who)
  360. {
  361.    if (who == RED)
  362.    {
  363.       if (joymouse_on) swapjoymouse(FALSE);
  364.       if (status & IN_GAME)
  365.          DrawText(9,JAM1,223,16,"Player 1");
  366.       else
  367.          DrawText(1,JAM1,223,16,"Player 1");
  368.       DrawText(1,JAM1,223,49,"Player 2");
  369.    } else {    /* who == WHITE */
  370.       if (joymouse_allowed && !joymouse_on)  swapjoymouse(TRUE);
  371.       DrawText(1,JAM1,223,16,"Player 1");
  372.       if (status & IN_GAME)
  373.          DrawText(9,JAM1,223,49,"Player 2");
  374.       else
  375.          DrawText(1,JAM1,223,49,"Player 2");
  376.    }
  377. }
  378.